<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>穿梭框组件 transfer - Layui 文档</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script>;!function(){self!==parent&&(location.href="about:blank")}();</script>
  <link href="/public/layui/v/2.8.6/css/layui.css" rel="stylesheet">
  <link href="/public/static/dist/docs/2.8/css/global.css?v=16" rel="stylesheet">
  <script>
  (function(){if(window.JSON&&window.JSON.parse){var c=document.getElementsByTagName("head"),a=document.createElement("link");try{var b=JSON.parse(localStorage.layui)}catch(d){b={}}"dark"===b.themeMode&&(a.href="//res.sentcss.com/static/dist/docs/2.8/css/layui-theme-dark.css?v=16",a.rel="stylesheet",a.id="layuicss-theme-dark",c[0].appendChild(a))}})();
  </script>
</head>
<body>
<div class="layui-header ws-header ws-bg-light">
  <div class="layui-container">
    <div class="ws-logo">
      <a class="logo" href="../../../index.html">
        <img src="/public/static/images/layui/logo.png" alt="layui">
      </a>
    </div>
    <div class="ws-header-assist">
      <div class="layui-form layui-hide-xs ws-search" lay-filter="LAY-ws-header-component"></div>
      <div class="layui-hide-xs ws-notice"></div>
    </div>
    
    <div class="ws-header-menu">
      <ul class="layui-nav layui-bg-gray ws-bg-light" id="LAY_NAV_TOP">
        <li class="layui-nav-item" data-dir="docs">
          <a href="../index.html">组件</a> 
        </li>
        <li class="layui-nav-item" data-dir="notes">
          <a href="../../../notes/index.html">笔记</a> 
        </li>
        <li class="layui-nav-item layui-hide-xs">
          <a href="https://gitee.com/layui/layui/issues" target="_blank" rel="nofollow">社区</a>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">
            <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>--> 
            生态
          </a>
          <dl class="layui-nav-child layui-nav-child-r" style="margin-right: -21px;">  
            <dd class="layui-hide-sm layui-show-xs" lay-unselect>
              <a href="https://gitee.com/layui/layui/issues" target="_blank" rel="nofollow">社区</a>
              <hr>
            </dd>
            <dd lay-unselect>
              <a href="https://dev.layuion.com/extend/" target="_blank">Layui 第三方扩展组件</a>
            </dd>
            <dd lay-unselect>
              <a href="https://github.com/Sight-wcg/layui-theme-dark" target="_blank" lay-unselect>
                Layui 深色主题 <span>(社区贡献)</span>
              </a>
            </dd>
            <dd lay-unselect>
              <a href="https://gitee.com/layui/layui-vue/" target="_blank" lay-unselect>
                Layui of Vue <span>(他人实现)</span>
              </a>
            </dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">2.8.6</a>
          <dl class="layui-nav-child layui-nav-child-c">  
            <dd lay-unselect class="layui-this"><a href="../../../index.html">2.8.6</a></dd>
            <dd lay-unselect><a href="../../../2.7/index.html">2.7.6</a></dd>
          </dl>
        </li>
      </ul>
      <div class="ws-header-more">
        <i class="layui-icon layui-icon-shrink-right"></i>
      </div>
      <div class="ws-header-tool ws-bg-light">
        <div class="layui-form ws-header-theme" lay-filter="header-theme">
          <input type="checkbox" name="theme-mode" id="ID-header-theme-mode" lay-filter="header-theme-mode" lay-skin="switch">
          <div lay-checkbox>
            <i class="layui-icon layui-icon-moon"></i> | 
            <i class="layui-icon layui-icon-light"></i>
          </div>
        </div>
        <div>
          <a href="https://github.com/layui/layui" target="_blank" title="Github">
            <i class="layui-icon layui-icon-github layui-font-20"></i>
          </a>
        </div>
        <div>
          <a href="https://gitee.com/layui/layui" target="_blank" title="Gitee">
            <i class="layui-icon layui-icon-gitee layui-font-20" style="color: #C71D23;"></i>
            <!--<img src="https://gitee.com/static/images/logo-en.svg" width="21">-->
          </a>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 让 IE8/9 兼容响应式栅格 -->
<!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
 
<div class="layui-container ws-container">
  
<div class="layui-panel ws-menu">
  <ul class="layui-menu layui-menu-lg ws-docs-menu">
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">基础</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../index.html">
              <span>开始使用</span> 
              <span class="layui-font-12 layui-font-gray">Getting Started</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../base.html">
              <span>底层方法</span>
              <span class="layui-font-12 layui-font-gray">Base Function</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../modules.html">
              <span>模块系统</span>
              <span class="layui-font-12 layui-font-gray">Modules</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../versions.html">
              <span>更新日志</span>
              <span class="layui-font-12 layui-font-gray">Versions</span>
              <span class="layui-badge-dot"></span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">布局</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../layout/index.html">
              <span>框体</span>
              <span class="layui-font-12 layui-font-gray">Layout</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../layout/grid.html">
              <span>栅格</span>
              <span class="layui-font-12 layui-font-gray">Grid</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">通用</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../color/index.html">
              <span>颜色</span>
              <span class="layui-font-12 layui-font-gray">Color</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../button/index.html">
              <span>按钮</span>
              <span class="layui-font-12 layui-font-gray">Button</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../icon/index.html">
              <span>图标</span>
              <span class="layui-font-12 layui-font-gray">Icon</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../anim/index.html">
              <span>动画</span>
              <span class="layui-font-12 layui-font-gray">Anim</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">表单</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/index.html">
              <span>表单组件</span>
              <span class="layui-font-12 layui-font-gray">Form</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/input.html">
              <span>输入框</span>
              <span class="layui-font-12 layui-font-gray">Input / Textarea</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/select.html">
              <span>选择框</span>
              <span class="layui-font-12 layui-font-gray">Select</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/checkbox.html">
              <span>复选框</span>
              <span class="layui-font-12 layui-font-gray">Checkbox</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/radio.html">
              <span>单选框</span>
              <span class="layui-font-12 layui-font-gray">Radio</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">展示</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../table/index.html">
              <span>表格</span>
              <span class="layui-font-12 layui-font-gray">Table</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../laypage/index.html">
              <span>分页</span>
              <span class="layui-font-12 layui-font-gray">Laypage</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../treeTable/index.html">
              <span>树形表格</span>
              <span class="layui-font-12 layui-font-gray">TreeTable</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../nav/index.html">
              <span>导航菜单</span>
              <span class="layui-font-12 layui-font-gray">Nav</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../menu/index.html">
              <span>基础菜单</span>
              <span class="layui-font-12 layui-font-gray">Menu</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../tab/index.html">
              <span>选项卡</span>
              <span class="layui-font-12 layui-font-gray">Tab</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../badge/index.html">
              <span>徽章</span>
              <span class="layui-font-12 layui-font-gray">Badge</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../auxiliar/index.html">
              <span>辅助</span>
              <span class="layui-font-12 layui-font-gray">Blockquote / Fieldset / hr</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../class/index.html">
              <span>公共类</span>
              <span class="layui-font-12 layui-font-gray">Class</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../panel/index.html">
              <span>面板</span>
              <span class="layui-font-12 layui-font-gray">Panel / Card / Collapse</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../progress/index.html">
              <span>进度条</span>
              <span class="layui-font-12 layui-font-gray">Progress</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../timeline/index.html">
              <span>时间线</span>
              <span class="layui-font-12 layui-font-gray">Timeline</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../fixbar/index.html">
              <span>固定条</span>
              <span class="layui-font-12 layui-font-gray">Fixbar</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../tree/index.html">
              <span>树组件</span>
              <span class="layui-font-12 layui-font-gray">Tree</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../carousel/index.html">
              <span>轮播</span>
              <span class="layui-font-12 layui-font-gray">Carousel</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../flow/index.html">
              <span>流加载</span>
              <span class="layui-font-12 layui-font-gray">Flow</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../code/index.html">
              <span>代码预览组件</span>
              <span class="layui-font-12 layui-font-gray">Code</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">交互</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../layer/index.html">
              <span>弹出层</span>
              <span class="layui-font-12 layui-font-gray">Layer</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../laydate/index.html">
              <span>日期与时间选择</span>
              <span class="layui-font-12 layui-font-gray">Laydate</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../upload/index.html">
              <span>上传</span>
              <span class="layui-font-12 layui-font-gray">Upload</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../dropdown/index.html">
              <span>下拉菜单</span>
              <span class="layui-font-12 layui-font-gray">Dropdown</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../colorpicker/index.html">
              <span>颜色选择器</span>
              <span class="layui-font-12 layui-font-gray">Colorpicker</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="index.html">
              <span>穿梭框</span>
              <span class="layui-font-12 layui-font-gray">Transfer</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../slider/index.html">
              <span>滑块</span>
              <span class="layui-font-12 layui-font-gray">Slider</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../rate/index.html">
              <span>评分</span>
              <span class="layui-font-12 layui-font-gray">Rate</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">其他</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../laytpl/index.html">
              <span>模板引擎</span>
              <span class="layui-font-12 layui-font-gray">Laytpl</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../util/index.html">
              <span>工具模块</span>
              <span class="layui-font-12 layui-font-gray">Util</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    
  </ul>
</div>

  <div class="ws-content">
    <div class="layui-text ws-text" id="WS-text">
      <h1>穿梭框组件</h1>
<blockquote class="layui-elem-quote">
<p>穿梭框组件 <code>transfer</code> 以左右栏 <code>checkbox</code> 列表为表现形式，可对列表进行选择并移动到另一栏。</p>
</blockquote class="layui-elem-quote">
<h2 id="examples" lay-toc="{hot: true}" style="margin-bottom: 0;">示例</h2>
<div>
<pre class="layui-code" lay-options="{preview: true, text: {preview: '基础效果'}, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-transfer-demo"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var transfer = layui.transfer;
  // 数据
  var data = [
    {"value": "1", "title": "李白"},
    {"value": "2", "title": "杜甫"},
    {"value": "3", "title": "苏轼"},
    {"value": "4", "title": "李清照"},
    {"value": "5", "title": "鲁迅", "disabled": true},
    {"value": "6", "title": "巴金"},
    {"value": "7", "title": "冰心"},
    {"value": "8", "title": "矛盾"},
    {"value": "9", "title": "贤心"}
  ];
  // 渲染
  transfer.render({
    elem: '#ID-transfer-demo',
    data: data
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-title" class="ws-anchor ws-bold">定义标题及数据源</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-transfer-demo-title"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var transfer = layui.transfer;
  // 数据
  var data = [
    {"value": "1", "title": "李白"},
    {"value": "2", "title": "杜甫"},
    {"value": "3", "title": "苏轼"},
    {"value": "4", "title": "李清照"},
    {"value": "5", "title": "鲁迅", "disabled": true},
    {"value": "6", "title": "巴金"},
    {"value": "7", "title": "冰心"},
    {"value": "8", "title": "矛盾"},
    {"value": "9", "title": "贤心"}
  ];
  // 渲染
  transfer.render({
    elem: '#ID-transfer-demo-title',
    title: ['候选文人', '获奖文人'],  //自定义标题
    data: data,
    // width: 150, // 定义宽度
    height: 210 // 定义高度
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-value" class="ws-anchor ws-bold">初始右侧数据</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-transfer-demo-value"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var transfer = layui.transfer;
  // 数据
  var data = [
    {"value": "1", "title": "瓦罐汤"},
    {"value": "2", "title": "油酥饼"},
    {"value": "3", "title": "炸酱面"},
    {"value": "4", "title": "串串香", "disabled": true},
    {"value": "5", "title": "豆腐脑"},
    {"value": "6", "title": "驴打滚"},
    {"value": "7", "title": "北京烤鸭"},
    {"value": "8", "title": "烤冷面"},
    {"value": "9", "title": "毛血旺", "disabled": true},
    {"value": "10", "title": "肉夹馍"},
    {"value": "11", "title": "臊子面"},
    {"value": "12", "title": "凉皮"},
    {"value": "13", "title": "羊肉泡馍"},
    {"value": "14", "title": "冰糖葫芦", "disabled": true},
    {"value": "15", "title": "狼牙土豆"}
  ];
  // 渲染
  transfer.render({
    elem: '#ID-transfer-demo-value',
    data: data,
    value: ["1", "3", "5", "7", "9", "11"]
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-showSearch" class="ws-anchor ws-bold">显示搜索框</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-transfer-demo-showSearch"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var transfer = layui.transfer;
  // 数据
  var data = [
    {"value": "1", "title": "李白"},
    {"value": "2", "title": "杜甫"},
    {"value": "3", "title": "苏轼"},
    {"value": "4", "title": "李清照"},
    {"value": "5", "title": "鲁迅", "disabled": true},
    {"value": "6", "title": "巴金"},
    {"value": "7", "title": "冰心"},
    {"value": "8", "title": "矛盾"},
    {"value": "9", "title": "贤心"}
  ];
  // 渲染
  transfer.render({
    elem: '#ID-transfer-demo-showSearch',
    data: data,
    title: ['文本墨客', '获奖文人'],
    showSearch: true
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-parseData" class="ws-anchor ws-bold">数据格式解析</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-transfer-demo-parseData"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var transfer = layui.transfer;
  // 渲染
  transfer.render({
    elem: '#ID-transfer-demo-parseData',
    parseData: function(res){
      return {
        "value": res.id, // 数据值
        "title": res.name, // 数据标题
        "disabled": res.disabled,  // 是否禁用
        "checked": res.checked // 是否选中
      }
    },
    data: [
      {"id": "1", "name": "李白"},
      {"id": "2", "name": "杜甫"},
      {"id": "3", "name": "苏轼"}
    ],
    height: 150
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-onchange" class="ws-anchor ws-bold">穿梭时的回调</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="ID-transfer-demo-onchange"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var transfer = layui.transfer;
  var layer = layui.layer;
  // 数据
  var data = [
    {"value": "1", "title": "李白"},
    {"value": "2", "title": "杜甫"},
    {"value": "3", "title": "苏轼"},
    {"value": "4", "title": "李清照"},
    {"value": "5", "title": "鲁迅", "disabled": true},
    {"value": "6", "title": "巴金"},
    {"value": "7", "title": "冰心"},
    {"value": "8", "title": "矛盾"},
    {"value": "9", "title": "贤心"}
  ];
  // 渲染
  transfer.render({
    elem: '#ID-transfer-demo-onchange',
    data: data,
    onchange: function(obj, index){
      var arr = ['左边', '右边'];
       // 查看被穿梭时的数据 --  仅用于演示
      layer.alert('来自 <strong>'+ arr[index] + '</strong> 的数据：'+ JSON.stringify(obj));
    }
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-inst" class="ws-anchor ws-bold">实例调用</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div class="layui-btn-container">
  <button type="button" class="layui-btn" lay-on="getData">获取右侧数据</button>
  <button type="button" class="layui-btn" lay-on="reload">重载实例</button>
</div>
<div id="ID-transfer-demo-inst"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var transfer = layui.transfer;
  var util = layui.util;
  var layer = layui.layer;
  // 数据
  var data = [
    {"value": "1", "title": "李白"},
    {"value": "2", "title": "杜甫"},
    {"value": "3", "title": "苏轼"},
    {"value": "4", "title": "李清照"},
    {"value": "5", "title": "鲁迅", "disabled": true},
    {"value": "6", "title": "巴金"},
    {"value": "7", "title": "冰心"},
    {"value": "8", "title": "矛盾"},
    {"value": "9", "title": "贤心"}
  ];
  // 渲染
  transfer.render({
    elem: '#ID-transfer-demo-inst',
    data: data,
    id: 'demo-inst' // 定义唯一索引
  });
  // 批量事件
  util.on('lay-on', {
    getData: function(othis){
      var getData = transfer.getData('demo-inst'); // 获取右侧数据
      layer.alert(JSON.stringify(getData)); 
    },
    reload:function(){
      //实例重载
      transfer.reload('demo-inst', {
        title: ['文人', '喜欢的文人'],
        value: ['2', '5', '9'],
        showSearch: true
      })
    }
  });
});
</script>
  </textarea>
</pre>
</div>
<h2 id="api" lay-toc="{hot: true}">API</h2>
<table class="layui-table">
<thead>
<tr>
<th>API</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>var transfer = layui.transfer</td>
<td>获得 <code>transfer</code> 模块。</td>
</tr>
<tr>
<td><a href="index.html#render">transfer.render(options)</a></td>
<td>transfer 组件渲染，核心方法。</td>
</tr>
<tr>
<td><a href="index.html#reload">transfer.reload(id, options)</a></td>
<td>重载实例</td>
</tr>
<tr>
<td><a href="index.html#getData">transfer.getData(id)</a></td>
<td>获得右侧数据</td>
</tr>
<tr>
<td><a href="index.html#set">transfer.set(options)</a></td>
<td>设定全局默认属性</td>
</tr>
</tbody>
</table class="layui-table">
<h3 id="render" lay-toc="{level: 2}">渲染</h3>
<p><code>transfer.render(options);</code></p>
<ul>
<li>参数 <code>options</code> : 基础属性配置项。<a href="index.html#options">#详见属性</a></li>
</ul>
<h3 id="options" lay-toc="{level: 2, hot: true}">属性</h3>
<div>
<table class="layui-table">
  <colgroup>
    <col width="150">
    <col>
    <col width="100">
    <col width="100">
  </colgroup>
  <thead>
    <tr>
      <th>属性名</th>
      <th>描述</th>
      <th>类型</th>
      <th>默认值</th>
    </tr> 
  </thead>
  <tbody>
    <tr>
<td>elem</td>
<td>
<p>绑定元素选择器或 DOM 对象</p>
</td>
<td>string/DOM</td>
<td>-</td>
    </tr>
    <tr>
<td>title</td>
<td>
<p>穿梭框左右面板头部标题</p>
</td>
<td>array</td>
<td>
<p><button class="layui-btn layui-btn-sm layui-btn-primary" lay-layer="{
  title: 'title 属性默认值',
  content: '<div>title: [\'列表一\',\'列表二\']</div>'
}">查看默认值</button></p>
</td>
    </tr>
    <tr>
<td>data</td>
<td>
<p>穿梭框的数据源。格式详见：<a href="index.html#options.data">#data 格式</a></p>
</td>
<td>array</td>
<td>-</td>
    </tr>
    <tr>
<td>value</td>
<td>
<p>初始选中的数据（右侧列表）</p>
</td>
<td>array</td>
<td>-</td>
    </tr>
    <tr>
<td>id</td>
<td>
<p>设置实例唯一索引，用于其他方法传参使用。</p>
</td>
<td>string</td>
<td>-</td>
    </tr>
    <tr>
<td>showSearch</td>
<td>
<p>是否开启搜索。支持以下可选值：</p>
<ul>
<li><code>false</code> 不开启搜索（默认）</li>
<li><code>true</code> 开启搜索，且匹配时不区分大小写</li>
<li><code>cs</code> 开启搜索，且匹配时区分大小写 <sup>2.7+</sup></li>
</ul>
</td>
<td>boolean<br>string</td>
<td>
<p><code>false</code></p>
</td>
    </tr>
    <tr>
<td>width</td>
<td>
<p>定义左右穿梭框宽度</p>
</td>
<td>number</td>
<td>
<p><code>200</code></p>
</td>
    </tr>
    <tr>
<td>height</td>
<td>
<p>定义左右穿梭框高度</p>
</td>
<td>number</td>
<td>
<p><code>360</code></p>
</td>
    </tr>
    <tr>
<td>text</td>
<td colspan="3">
<p>自定义默认文本， <code>object</code> 类型。支持以下属性：</p>
<pre><code class="layui-code">text: {
  none: '无数据', // 没有数据时的文案
  searchNone: '无匹配数据' // 搜索无匹配数据时的文案
} 
</code></pre>
</td>
    </tr>
    <tr>
<td colspan="4" style="text-align: center"> 
<div id="options.callback" lay-pid="options" class="ws-anchor">
<p><a href="index.html#options.callback">回调函数</a></p>
</div>
</td>
    </tr>
    <tr>
<td>onchange</td>
<td>
<p>左右穿梭时的回调函数。返回的参数如下：</p>
<pre><code class="layui-code">onchange: function(data, index){
  console.log(data); // 得到当前被穿梭的数据
  console.log(index); // 如果数据来自左边，index 为 0，否则为 1
}
</code></pre>
</td>
<td>boolean</td>
<td>
<p><code>false</code></p>
</td>
    </tr>
    <tr>
<td>
<p><a href="index.html#options.parseData">parseData</a></p>
</td>
<td colspan="3">
<div id="options.parseData" lay-pid="options" class="ws-anchor">
数据格式解析的回调函数，用于将返回的任意数据格式解析成 transfer 组件规定的 <a href="index.html#options.data">data 格式</a>
</div>
<pre><code class="layui-code">transfer.render({
  elem: '',
  data: [ // 任意数据
    {&quot;id&quot;: &quot;1&quot;, &quot;name&quot;: &quot;李白&quot;},
    {&quot;id&quot;: &quot;2&quot;, &quot;name&quot;: &quot;杜甫&quot;},
    {&quot;id&quot;: &quot;3&quot;, &quot;name&quot;: &quot;贤心&quot;}
  ],
  parseData: function(res){ // 解析成规定的 data 格式
    return {
      &quot;value&quot;: res.id, // 数据值
      &quot;title&quot;: res.name, // 数据标题
      &quot;disabled&quot;: res.disabled,  // 是否禁用
      &quot;checked&quot;: res.checked // 是否选中
    };
  }
});
</code></pre>
</td>
    </tr>
  </tbody>
</table>
</div>
<h3 id="options.data" lay-toc="{level: 3, hot: true}">data 格式</h3>
<div>
<table class="layui-table">
  <colgroup>
    <col width="150">
    <col>
    <col width="100">
    <col width="100">
  </colgroup>
  <thead>
    <tr>
      <th>属性名</th>
      <th>描述</th>
      <th>类型</th>
      <th>默认值</th>
    </tr> 
  </thead>
  <tbody>
    <tr>
<td>title</td>
<td>
<p>数据标题</p>
</td>
<td>string</td>
<td>-</td>
    </tr>
    <tr>
<td>value</td>
<td>
<p>数据值</p>
</td>
<td>string</td>
<td>-</td>
    </tr>
    <tr>
<td>checked</td>
<td>
<p>是否选中状态</p>
</td>
<td>boolean</td>
<td>
<p><code>false</code></p>
</td>
    </tr>
    <tr>
<td>disabled</td>
<td>
<p>是否禁用状态</p>
</td>
<td>boolean</td>
<td>
<p><code>false</code></p>
</td>
    </tr>
  </tbody>
</table>
</div>
<h3 id="reload" lay-toc="{level: 2}">重载</h3>
<p><code>transfer.reload(id, options);</code></p>
<ul>
<li>参数 <code>id</code> : 对应渲染时定义的 <code>id</code> 属性值</li>
<li>参数 <code>options</code> : 基础属性配置项。<a href="index.html#options">#详见属性</a></li>
</ul>
<pre><code class="layui-code">var transfer = layui.transfer;
// 渲染
transfer.render({
  elem: '', // 绑定元素选择器
  id: 'test', // 自定义 id 索引
  // 其他属性 …
});
// 重载
transfer.reload('test', { // options
  title: ['title 1', 'title 2']
});
</code></pre>
<h3 id="getData" lay-pid="api" class="ws-anchor ws-bold">获得右侧数据</h3>
<p><code>transfer.getData(id);</code></p>
<ul>
<li>参数 <code>id</code> : 对应渲染时定义的 <code>id</code> 属性值</li>
</ul>
<p>穿梭框的右侧数据通常被认为是选中数据，因此你需要得到它，并进行提交等操作。</p>
<pre><code class="layui-code">var transfer = layui.transfer;
// 渲染
transfer.render({
  elem: '', // 绑定元素选择器
  id: 'test', // 自定义 id 索引
  // 其他属性 …
});
// 获得右侧数据
var getData = transfer.getData('test');
</code></pre>
<h3 id="set" lay-pid="api" class="ws-anchor ws-bold">设置全局默认属性</h3>
<p><code>transfer.set(options);</code></p>
<ul>
<li>参数 <code>options</code> : 基础属性配置项。<a href="index.html#options">#详见属性</a></li>
</ul>
<p>该方法对所有的 <code>transfer</code> 实例有效，设置的属性优先级低于 <code>transfer.render(options)</code></p>
<pre><code class="layui-code">// 设置 transfer 全局默认属性
transfer.set({
  height: 'auto', // 所有穿梭框默认高度为自动
  // …
});
</code></pre>

    </div>
    <div class="ws-text-tools">
      
      <a href="https://github.com/layui/layui/edit/2.x/docs/transfer/index.md" rel="nofollow" target="_blank" title="在 Github 上编辑此文档">
        <i class="layui-icon layui-icon-edit"></i>
      </a>
      
    </div>
  </div>
</div>
<div class="ws-menu-bar layui-bg-green layui-hide">
  <i class="layui-icon layui-icon-spread-left"></i>
</div>
  
<div class="layui-footer ws-footer">
  <p>
    Copyright &copy; 2023 <a href="../../../index.html">Layui</a> MIT Licensed</p>
  <p id="LAY-footer-info">
    <a href="https://gitee.com/layui/layui/blob/main/DISCLAIMER.md" rel="nofollow" target="_blank">免责声明</a> 
    <a href="https://github.com/layui/layui/blob/main/LICENSE" rel="nofollow" target="_blank">开源协议</a>
    <a href="https://gitee.com/layui/" target="_blank">开源生态</a>
    <a href="https://codepen.io/layui/pen/bGxZXrd" rel="nofollow" target="_blank">在线测试</a>
    <a href="https://gitee.com/layui/layui/issues" rel="nofollow" target="_blank">社区交流</a>
  </p>
  <p>
    <span>
      鸣谢：
      <a href="https://www.upyun.com/?invite=SJ0wu6g2-&referer=layui" target="_blank" sponsor="upyun" style="color: #23A7E8;">
        <strong>又拍云</strong>
      </a>
      <a href="https://gitee.com/?referer=layui" target="_blank" sponsor="Gitee" style="color:#C71D23;">
        <strong>Gitee</strong>
      </a>
      <a href="https://www.iconfont.cn/?referer=layui" target="_blank" sponsor="Gitee" style="color: #9B16FF;">
        <strong>iconfont</strong>
      </a>
    </span>
  </p>
</div>
<div class="ws-shade"></div>
 
<script src="/public/layui/v/2.8.6/layui.js"></script>
<script>
layui.config({
  base: '//res.sentcss.com/static/dist/docs/2.8/modules/',
  version: '16',
  res: '//res.sentcss.com/static/dist/docs/',
  curl: ''
}).use('global',function(w){w.a||w.r&&w.r()});
</script>
 
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?363b2abe8678eec8a6850500ea63a63b";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</body>
</html>